package com.jav.util;

/*
 * @author Javier A. Ramírez M.
 * jaramirez85@yahoo.es
 * Fecha : 24/feb/2010 10:43 pm
 */

public class StringUtils {
    public static String lpad(String cadena, char filler, int size) {

        cadena = cadena != null ? cadena :"";
        size = size >= 0 ? size :0;

        if (cadena.length() > size){
            return cadena.substring(0,size);
        }
        else{
            return repeat(filler, size - cadena.length()) + cadena;
        }
    }

    public static String rpad(String cadena, char filler, int size) {
        cadena = cadena != null ? cadena :"";
        size = size >= 0 ? size :0;
        if (cadena.length() > size){
            return cadena.substring(0,size);
        }
        else{
            return cadena + repeat(filler,  size - cadena.length());
        }
    }

    public static String repeat( char filler, int size){
        StringBuffer rep = new StringBuffer();
        while (rep.length() < size){
            rep.append(filler);
        }

        return rep.toString();
    }

}
